package com.my.study.structures.linkedlist;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/6/7 22:55
 **/
@Slf4j(topic = "c.SingleDemo")
public class SingleDemo {

    public static void main(String[] args) {
        SingleLinkedList linkedList = new SingleLinkedList();

        linkedList.add(1, "宋江", "及时雨");
        linkedList.add(2, "吴用", "智多星");
        linkedList.add(3, "卢俊义", "玉麒麟");

        linkedList.list();


        // 获取有效节点数
        int length = linkedList.getLength(linkedList.getHead());
        log.debug("有效个数 {}", length);

        // 获取单链表倒数第k个节点
        SingleLinkedList.HeroNode lastIndexNode = linkedList.findLastIndexNode(linkedList.getHead(), 1);
        log.debug("倒数第{}个节点为 {}", 1, lastIndexNode);

        // 单链表反转
//        linkedList.reverse(linkedList.getHead());
//        linkedList.list();

        // 逆序打印链表，不改变链接结构
        linkedList.reversePrint(linkedList.getHead());

    }
}
